home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / mint / mint104s.zoo / mint.src / trans.c < prev    next >
C/C++ Source or Header  |  1993-03-08  |  3KB  |  197 lines

  1. /*
  2.  * translation routines; sometimes we pass data on
  3.  * through directly (asm syntax->asm syntax, with
  4.  * some macro expansion), and other times we also
  5.  * do asm syntax->gas syntax translation
  6.  */
  7.  
  8. #include "asmtrans.h"
  9.  
  10. int syntax = GAS;
  11.  
  12. char *
  13. immediate(op)
  14.     char *op;
  15. {
  16.     return concat("#", op);
  17. }
  18.  
  19. char *
  20. indirect(op)
  21.     char *op;
  22. {
  23.     if (syntax == GAS) {
  24.         return concat(op, "@");
  25.     } else {
  26.         return concat3("(", op, ")");
  27.     }
  28. }
  29.  
  30. char *
  31. postinc(op)
  32.     char *op;
  33. {
  34.     if (syntax == GAS) {
  35.         return concat(op, "@+");
  36.     } else {
  37.         return concat3("(", op, ")+");
  38.     }
  39. }
  40.  
  41. char *
  42. predec(op)
  43.     char *op;
  44. {
  45.     if (syntax == GAS) {
  46.         return concat(op, "@-");
  47.     } else {
  48.         return concat3("-(", op, ")");
  49.     }
  50. }
  51.  
  52. char *
  53. indexed(op1, op2)
  54.     char *op1, *op2;
  55. {
  56.     if (syntax == GAS) {
  57.         return concat4(op2, "@(", op1, ")");
  58.     } else {
  59.         return concat4(op1, "(", op2, ")");
  60.     }
  61. }
  62.  
  63. char *
  64. sizedop(op, size)
  65.     char *op, *size;
  66. {
  67.     if (syntax == GAS) {
  68.         return changesiz(concat(op, size));
  69.     } else {
  70.         return concat4("(", op, ")", size);
  71.     }
  72. }
  73.  
  74. char *
  75. twoindex(disp, base, index)
  76.     char *disp, *base, *index;
  77. {
  78.     if (syntax == GAS) {
  79.         return concat6(base, "@(", disp, ",", changesiz(index), ")");
  80.     } else {
  81.         return concat6(disp, "(", base, ",", index, ")");
  82.     }
  83. }
  84.  
  85. char *
  86. bitfield(op1, op2, op3)
  87.     char *op1, *op2, *op3;
  88. {
  89.     if (syntax == GAS) {
  90.         return concat6(op1, "{#", op2, ":#", op3, "}");
  91.     } else {
  92.         return concat6(op1, "{", op2, ":", op3, "}");
  93.     }
  94. }
  95.  
  96. char *
  97. do_ops(label, opcode, space, operand)
  98.     char *label, *opcode, *space, *operand;
  99. {
  100.     static char temp[LINSIZ];
  101.     static char optemp[40];
  102.     char *to, *from;
  103.     char c;
  104.  
  105.     if (syntax == GAS) {
  106.         if (!strcmp(opcode, "ds.l")) {
  107.         strcpy(temp, "\t.even\n\t.comm");
  108.         strcat(temp, space);
  109.         strcat(temp, label);
  110.         strcat(temp, ",");
  111.         strcat(temp, "4*");
  112.         strcat(temp, operand);
  113.         return strdup(temp);
  114.         } else if (!strcmp(opcode, "ds.w")) {
  115.         strcpy(temp, "\t.even\n\t.comm");
  116.         strcat(temp, space);
  117.         strcat(temp, label);
  118.         strcat(temp, ",");
  119.         strcat(temp, "2*");
  120.         strcat(temp, operand);
  121.         return strdup(temp);
  122.         } else if (!strcmp(opcode, "ds.b")) {
  123.         strcpy(temp, "\t.comm");
  124.         strcat(temp, space);
  125.         strcat(temp, label);
  126.         strcat(temp, ",");
  127.         strcat(temp, operand);
  128.         return strdup(temp);
  129.         } else {
  130.         to = optemp;
  131.         from = opcode;
  132.         for(;;) {
  133.             c = *from++;
  134.             if (!c) break;
  135.     /* change 'foo.b' -> 'foob' */
  136.     /* special case: bra.s -> 'bra', since gas automatically
  137.      * selects offset sizes and since some gas's actually
  138.      * mess up if an explicit '.s' is given
  139.      */
  140.             if (c == '.' && *from && from[1] == 0) {
  141.                 if (*from == 's') from++;
  142.                 continue;
  143.             }
  144.             *to++ = c;
  145.         }
  146.         *to = 0;
  147.         opcode = optemp;
  148.         }
  149.     }
  150.  
  151.     to = temp;
  152.  
  153.     if (*label) {
  154.         int colonseen = 0;
  155.         char c;
  156.  
  157.         for (from = label; (c = *from++) != 0;) {
  158.             if (c == ':') colonseen = 1;
  159.             *to++ = c;
  160.         }
  161. /* gas labels must have a ':' after them */
  162.         if (!colonseen && syntax == GAS)
  163.             *to++ = ':';
  164.     }
  165.  
  166.     *to++ = '\t';
  167.     strcpy(to, opcode);
  168.     strcat(temp, space);
  169.     strcat(temp, operand);
  170.     return strdup(temp);
  171. }
  172.  
  173. char *
  174. changesiz(op)
  175.     char *op;
  176. {
  177.     char *r = op;
  178.  
  179.     if (syntax != GAS) return op;
  180.  
  181.     while (*op) {
  182.         if (*op == '.') *op = ':';
  183.         op++;
  184.     }
  185.     return r;
  186. }
  187.  
  188. char *
  189. hexop(op)
  190.     char *op;
  191. {
  192.     if (syntax == GAS)
  193.         return concat("0x", op);
  194.     else
  195.         return concat("$", op);
  196. }
  197.